<%@include  file="/WEB-INF/header.jsp"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
     <!-- 用户列表  start-->
	<div id="page-wrapper">
		<div class="row">
			<div class="col-lg-12">
				<h1 class="page-header">商品分类管理</h1>
			</div>
			<!-- /.col-lg-12 -->
		</div>
		<!-- /.row -->

		<a href="#" class="btn btn-primary" data-toggle="modal" 
		           data-target="#newCateDialog" >新建</a>
		
		<div class="row">
			<div class="col-lg-12">
				<div class="panel panel-default">
					<div class="panel-heading">商品信息列表</div>
					<!-- /.panel-heading -->
					<table class="table table-bordered table-striped">
						<thead>
							<tr>
								<th>序号</th>
								<th>分类名</th>
								<th>分类描述</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody>
							<c:forEach items="${clist}" var="c">
								<tr>
									
									<td>${c.cate_id}</td>
									<td>${c.cate_name}</td>
									<td>${c.cate_desc}</td>
									<td>
									<a href="#" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#editModal" role="button" onclick="edit('${c.cate_name }')">修改</a>
										<a href="${pageContext.request.contextPath }/user/delC.action?cate_id=${c.cate_id }" class="btn btn-danger btn-xs" role="button" onclick="JavaScript:return confirm('确实要删除该用户信息吗？')">删除</a>
									</td>
								</tr>
							</c:forEach>
						</tbody>
					</table>
					<div class="col-md-12 text-right">
						<pagebar:page url="${pageContext.request.contextPath }/goods/list.action" />
					</div>
					<!-- /.panel-body -->
				</div>
				<!-- /.panel -->
			</div>
			<!-- /.col-lg-12 -->
		</div>
	</div>
	<!-- 用户列表  end-->
</div>

<!-- 创建用户模态框 -->
	<form class="form-horizontal" id="new_cate_form">
<div class="modal fade" id="newCateDialog" tabindex="-1" role="dialog"
	 aria-labelledby="myModalLabel">
	<div class="modal-dialog" role="document">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Close">
					<span aria-hidden="true">&times;</span>
				</button>
				<h4 class="modal-title" id="myModalLabel">新建分类</h4>
			</div>
			<div class="modal-body">

					<div class="form-group">
						<label for="new_catename" class="col-sm-2 control-label">
							分类名：
						</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="new_catename" placeholder="请输分类" name="cate_name" />
						</div>
					</div>
					<div class="form-group">
						<label for="new_desc" class="col-sm-2 control-label">新描述：</label>
						<div class="col-sm-10">
							<input type="text" class="form-control" id="new_desc" placeholder="请输入描述" name="cate_desc" />
						</div>
					</div>
			</div>
			<div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
				<button type="button" class="btn btn-primary" onclick="addCate()">创建用户</button>
			</div>

		</div>
	</div>
</div>
</form>

<form class="form-horizontal" id="new_cate1_form">
<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">修改用户信息</h4>
            </div>
            <div class="modal-body">
            
			  <div class="form-group">
			    <label for="firstname" class="col-sm-2 control-label">分类名</label>
			    <div class="col-sm-10">
			      <input type="text" class="form-control" id="catename" name="catename" placeholder="请输入分类名">
			    </div>
			  </div>
			  <div class="form-group">
			    <label for="lastname" class="col-sm-2 control-label">描述</label>
			    <div class="col-sm-10">
			      <input type="text" class="form-control" id="desc" name="desc" placeholder="请输描述">
			    </div>
			  </div>
 			 
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="submit" class="btn btn-primary" onclick="updateCate()">提交更改</button>
            </div>
            <input type="text" class="form-control" id="cate_id" name="cate_id">
            
      </div>
        </div>
    </div>
</form>   
    <script>
 // 执行修改用户操作
    </script>
</div>
<script>
//通过id获取修改的用户信息
function edit(cate_id) {
	$.post("${pageContext.request.contextPath}/user/getCateById.do",{"cate_id":cate_id},function(data){
         $("#edit_cateename").val(data.cate_name);
         $("#edit_catedesc").val(data.cate_desc);
         $("#edit_cateid").val(data.cate_id);
         //$("#form_username").show();
         //$("#form_userpass").show();
         //$("select option[value='"+data.parentid+"']").attr("selected", "selected");  
	},"json");
}
// 执行修改用户操作
function updateCate() {
	$.post("${pageContext.request.contextPath}/category/updateCate.action",
			$("#new_cate1_form").serialize(),function(data){
		if(data =="OK"){
			alert("用户信息更新成功！");
			window.location.reload();
		}else{
			alert("用户信息更新失败！");
			window.location.reload();
		}
	});
}

function addCate() {
	alert("ccc");
	$.post("${pageContext.request.contextPath}/user/addCate.action",
			$("#new_cate_form").serialize(),function(data){
				if(data =="OK"){
					alert("用户创建成功！");
					window.location.reload();
				}else{
					alert("用户创建失败！");
					window.location.reload();
				}

			});
}
</script>

 <%@include  file="/WEB-INF/footer.jsp"%>